/**
 * 
 */
package com.morningstar.qs.api.basic.common.response;

import org.apache.log4j.Logger;

import com.mstar.qs.common.json.JsonBean;
import com.mstar.qs.common.json.JsonException;

/**
 * @author rzeng
 *
 */
public class ErrorResponse {
	private static Logger gLogger =Logger.getLogger(ErrorResponse.class);
	
	public static final String RESPONSE_JSON_DEFAULT_STRING = "{}";
	public static final String RESPONSE_XML_DEFAULT_STRING = "<>";
	
	public static final String RESPONSE_FIELD_VALUE_EMPTY_STRING = "";
	
	public static final String RESPONSE_KEY_ERROR_CODE = "errorCode";
	public static final String RESPONSE_KEY_ERROR_MESSAGE = "errorMessage";
	
	public static final int RESPONSE_ERROR_CODE_0 = 0;
	public static final int RESPONSE_ERROR_CODE_COMMON = 9999;
	
	public static final String RESPONSE_ERROR_MESSAGE_COMMON = "An common error.";
	
	/**
	 * @deprecated
	 */
	public ErrorResponse() {
	}
	
	public static class ErrorBean{
		private String errorCode;
		private String errorMessage;
		public String getErrorCode() {
			return errorCode;
		}
		public void setErrorCode(String errorCode) {
			this.errorCode = errorCode;
		}
		public String getErrorMessage() {
			return errorMessage;
		}
		public void setErrorMessage(String errorMessage) {
			this.errorMessage = errorMessage;
		}
		
	}
	
	/**
	 * @deprecated
	 * format an error to a JSON string
	 * @param errorCode
	 * @param errorMessage
	 * @return a JSON string of error occurred
	 */
	public static String formatErrorToJSON(String errorCode, String errorMessage) {
		ErrorBean eb=new ErrorBean();
		eb.setErrorCode(errorCode);
		eb.setErrorMessage(errorMessage);
		return new JsonBean(eb, null, null).toString();
		/*String resp = "";
		try {
			JSONObject jsError = new JSONObject();
			jsError.put(RESPONSE_KEY_ERROR_CODE, errorCode);
			jsError.put(RESPONSE_KEY_ERROR_MESSAGE, errorCode);
			resp = jsError.toString();
		} catch (JsonException e) {
			gLogger.error("", e);
		}
		return resp;*/
	}
}
